/*
 * =====================================================================================
 *
 *       Filename:  writen.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  10/03/11 19:53:08
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */

#include "unp.h"

ssize_t writen(int fd, const void* vptr , size_t n){
    size_t nleft;
    ssize_t nwritten;
    const char* ptr;

    ptr = (char*)vptr;
    nleft = n;

    while(nleft > 0){
        if( (nwritten = write(fd, ptr, nleft)) <= 0){
            if(errno == EINTR)
                nwritten = 0;
            else
                return (-1);
        }

        nleft -= nwritten;
        ptr   += nwritten;
    }

    return (n);

}


void Writen(int fd , void* ptr , size_t nbytes){
    if(writen(fd,ptr,nbytes) != nbytes)
        ;//report errors
}
